<template>
    <div class="field-statistics">
        <template v-if="tableData1.length">
            <title-bar title="连续型字段分析统计"></title-bar>
            <el-table border :data="tableData1" tooltip-effect="dark" max-height="400px">
                <template slot="empty">
                    <no-data :types="false">
                        <span>暂无数据</span>
                    </no-data>
                </template>
                <el-table-column prop="experimentName" label="序号" type="index" width="60px"></el-table-column>
                <el-table-column v-for="(item, index) in fields1" :key="index" :prop="item.prop" :label="item.label" show-overflow-tooltip></el-table-column>
            </el-table>
        </template>
        <template v-if="tableData2.length">
            <title-bar title="离散型字段分析统计"></title-bar>
            <el-table border :data="tableData2" tooltip-effect="dark" max-height="400px">
                <template slot="empty">
                    <no-data :types="false">
                        <span>暂无数据</span>
                    </no-data>
                </template>
                <el-table-column prop="experimentName" label="序号" type="index" width="60px"></el-table-column>
                <el-table-column v-for="(item, index) in fields2" :key="index" :prop="item.prop" :label="item.label" show-overflow-tooltip></el-table-column>
            </el-table>
        </template>
    </div>
</template>
<script>
import {
    mapGetters
} from 'vuex'
import TitleBar from '@/components/TitleBar'
import NoData from '@/components/NoData'
export default {
    name: 'FieldStatistics',
    components: { NoData, TitleBar },
    computed: {
        ...mapGetters({
            analysisReportData: 'common/getAnalysisReportData'
        })
    },
    data () {
        return {
            tableData1: [],
            fields1: [
                { prop: '名称', label: '字段名称' },
                { prop: '数据类型', label: '数据类型' },
                { prop: '总数', label: '总数' },
                { prop: '缺失值', label: '缺失值占比' },
                { prop: '0值', label: '0值占比' },
                { prop: '最小值', label: '最小值' },
                { prop: '最大值', label: '最大值' },
                { prop: '均值', label: '均值' },
                { prop: '方差', label: '方差' },
                { prop: '标准差', label: '标准差' },
                { prop: '偏度', label: '偏度' },
                { prop: '峰度', label: '峰度' }
            ],
            tableData2: [],
            fields2: [
                { prop: '名称', label: '字段名称' },
                { prop: '数据类型', label: '数据类型' },
                { prop: '总数', label: '总数' },
                { prop: '缺失值', label: '缺失值占比' },
                { prop: '众数', label: '众数' }
            ]
        }
    },
    created () {
        let arr = this.analysisReportData.content
        let arr1 = []
        let arr2 = []
        for (let i = 0; i < arr.length; i++) {
            arr[i]['特征类型'] === '连续型' ? arr1.push(arr[i]) : arr2.push(arr[i])
        }
        this.tableData1 = arr1
        this.tableData2 = arr2
    }
}
</script>
